




const _order = {
    ordePay:function (orderId) {
        $.ajax({
            type:'POST',
            url: _common_util.getServerURL('order/order_payment'),
            dataType:'json',
            data:{
                'orderId':orderId
            },
            success : function (res) {
                console.log('orderpay');
                console.log(res);
                if (res.status=== 0 ){
                    window.wxc.xcConfirm("支付成功，即将跳转至订单详情",'info',{onOk: function () {
                            setTimeout(_common_util.showOrderDetail(orderId),5000)
                        }});
                }else if (res.status === 22){
                    window.wxc.xcConfirm('余额不足，无法完成支付');
                }
            }
        })
    },

    AliPay:function (orderId) {

        window.open(_common_util.getServerURL('orderpay.html?orderId='+orderId),'WIPaypal','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=650, height=650');
    }
}


$(function () {


    let orderId = _common_util.getURLParam('orderId');

    $.ajax({
        type: 'GET',
        url :  _common_util.getServerURL('order/customer_order_detail?orderId=')+orderId,
        success:function (res) {
            console.log(res);
            if (res.status === 3){
                window.wxc.xcConfirm('尚未登录，请先登录','info',function () {
                    window.location.href='my-account.html';
                })
            }else if (res.status === 0 ){
                //todo 取到data，通过list，生成表格里的每一行

                $.ajax({
                    type        :  'get',
                    url         :  "http://localhost:8080/admin/get_account",
                    dataType    :  'json',
                    success:function (res) {
                        $('.receive-name').html(res.data.username);
                        $('.user-balance').html(res.data.balance);

                    }
                })


                $('.orderId').html(res.data.orderId);
                $('.order-date').html(res.data.createTime);
                $('.order-state').html(res.data.orderState);
                $('.product-name-count').html(res.data.itemName+"✖️"+res.data.itemNumber);
                $('.product-total').html( res.data.itemNumber * res.data.unitPrice);
                $('.order-total').html(res.data.itemNumber * res.data.unitPrice);
                $('.receive-phone').html(res.data.cphone);
                $('.receive-address').html(res.data.caddress);


            }
        }
    })


    $('#orderpay').on('click',function () {
        console.log('click_orderpay');
        let orderId = _common_util.getURLParam('orderId');

        if ($('#payment_method_bacs').is(':checked') ){
            _order.ordePay(orderId);
        }else if ($('#payment_method_alipay').is(':checked')){
            _order.AliPay(orderId);
        }
    })
})



